﻿<%@ page import="java.util.List" %>
<%@ page import="code.entity.Location" %>
<%@ page import="code.service.LocationService" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    try {
        String date = request.getParameter("date") == null ? "" : request.getParameter("date");
        String username = request.getParameter("username") == null ? "" : request.getParameter("username");
        List<Location> list = new ArrayList<Location>();

        if (date.trim().length() > 0 && username.trim().length() > 0) {
            list = LocationService.getLocationList(date, username);
        }


        int count = list.size();
        int totalPage = 0, pageSize = 10;
        totalPage = count % pageSize == 0 ? count / pageSize : (count / pageSize) + 1;
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
    <title>留下你我的足迹</title>
    <link rel=stylesheet type=text/css href="ui/css/layout.css"/>
    <script type="text/javascript" src="ui/js/jquery.js"></script>
    <script type="text/javascript" src="ui/js/layout.js"></script>
    <script type="text/javascript" src="ui/js/page.js"></script>
    <script type="text/javascript" src="ui/js/My97DatePicker/WdatePicker.js" ></script>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
</head>
<body>
<table height="100%" width="100%" border="0" cellpadding="0" cellspacing="0">
    <tbody>
    <tr>

        <td id="data_list">
            <form action="bmap.jsp">
                <div>
                <label for="username">昵称</label>
                <input id="username" name="username" value="<%=username%>" maxlength="11" style="width:140px"/>
                </div>

                <div>
                <label for="date">日期</label>
                <input id="date" name="date" value="<%=date%>" maxlength="10" style="width:140px"
                       class="Wdate" onfocus="new WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
                </div>

                <input type="submit" value="查 询">
            </form>
            <div id="markers">
                <%
                    for (int i = 0; i < list.size(); i++) {
                        Location l = list.get(i);
                        if (i >= 10) break;
                %>

                <p><a href="javascript:void(0);"
                      onclick="addMarker('<%=l.getX()%>','<%=l.getY()%>');"><%=l.getCreateTime()%>
                </a></p>
                <%}%>

                <%if (totalPage > 1) {%>
                <a href="javascript:void(0);" onclick="prev(this);" page="1" totalPage="<%=totalPage%>"
                   url="markers.jsp" list="markers" data="&date=<%=date%>&username=<%=username%>">上一页</a>
                1/<%=totalPage%>
                <a href="javascript:void(0);" onclick="next(this);" page="1" totalPage="<%=totalPage%>"
                   url="markers.jsp" list="markers" data="&date=<%=date%>&username=<%=username%>">下一页</a>
                <%}%>
            </div>
            <br/>
            <br/>

            <div id="loading" align="left"></div>
        </td>
        <td id="side_bar" onclick="sidebarOnclick();" title="隐藏侧边栏"></td>

        <td id="data_map">
            <div id="container" style="width:100%; height:100%"></div>
            &nbsp;

        </td>
    </tr>
    </tbody>
</table>

</body>
</html>
<script type="text/javascript">
    document.oncontextmenu = new Function("event.returnValue=false;");
    document.onselectstart = new Function("event.returnValue=false;");
    var map = new BMap.Map("container");
    <%if(list!=null&&list.size()>0){%>
    var point = new BMap.Point(<%=list.get(0).getX()%>, <%=list.get(0).getY()%>);
    <%}else{%>
    var point = new BMap.Point(113.95590756, 22.57144636);
    <%}%>


    map.centerAndZoom(point, 15);
    map.addControl(new BMap.ScaleControl());
    map.addControl(new BMap.NavigationControl());

    var polyline = new BMap.Polyline([
        <%
           for(int i=0;i<list.size();i++){
             Location l=list.get(i);
        %>
        new BMap.Point(<%=l.getX()%>, <%=l.getY()%>)<%=i==list.size()-1?"":","%>
        <%}%>
    ], {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});
    map.addOverlay(polyline);


    var marker;
    var img = new BMap.Icon("images/dot.gif", new BMap.Size(18, 18));
    function addMarker(x, y) {
        map.removeOverlay(marker);
        point = new BMap.Point(x, y);
        marker = new BMap.Marker(point, {icon:img});
        map.addOverlay(marker);
    }
</script>

<%
    } catch (Exception e) {
        e.printStackTrace();
    }
%>